<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>产品配置</el-breadcrumb-item>
        <el-breadcrumb-item>广告解锁配置</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
        @row-update="rowUpdate"
        @row-save="rowSave"
  
      >
        <!--自定义表单 -->
        <template slot="last" slot-scope="scope">
          {{ scope.row.edit_time }}
          <el-tag>{{ scope.row.edit_admin_name }}</el-tag>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>


<script>
import { common } from "@/api/cat/httpRequest";
import {
  appConfigAdUnlock as baseURL
} from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10,
      },
      cardTypeList: [],
      moduleList: [],
      type: true,
      data: [],
      params: {},
      form: {},
      message: "",
      default: {
        orderByList: "language&ASC",
      },
      option: {
        addBtn: false,
        border: true,
        selection: true,
        border: true,
        delBtn: false,
        editBtn: true,
        align: "center",
        headerAlign: "center",
        index: true,
        indexLabel: "编号",
        column: [
          {
            label: "语言",
            prop: "language",
            type: "select",
            placeholder: "请选择语言",
            addDisabled: true,
            editDisabled: true,
            dicData: [
              {
                label: "英语",
                value: 2,
              },
              {
                label: "芬兰语",
                value: 3,
              },
            ],
            props: {
              label: "label",
              value: "value",
            },
            rules: [
              {
                required: true,
                message: "语言必须填写",
              },
            ],
          },
          {
            label: "单本书广告解锁次数",
            prop: "unlock_times",
            type: "number",
          },
          {
            label: "单次广告解锁章节",
            prop: "unlock_chapter_num",
            type: "number",
          },
          {
            label: "最后操作信息",
            prop: "last",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
            editDisabled: false,
            readonly: true,
            slot: true,
          },
        ],
      },
    };
  },
  methods: {
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(
        `${baseURL.pageAndParam}`,
        { ...this.params, ...this.default },
        this.page,
        "POST"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    },
    /**保存 */
    async rowSave(row, done, loading) {
      delete row["id"];
      let userInfo = this.$store.state.user.userInfo;
      row.edit_admin_name = userInfo.username;
      row.edit_admin_id = userInfo.id;
      let data = await common(`${baseURL.save}`, row, null, "POST");
      loading();
      if (data == null) {
        return;
      }
      this.getList();
      done();
    },
    /**修改 */
    async rowUpdate(row, index, done, loading) {
      let userInfo = this.$store.state.user.userInfo;
      row.edit_admin_name = userInfo.username;
      row.edit_admin_id = userInfo.id;
      let data = await common(`${baseURL.update}`, row, null, "POST");
      loading();
      if (data == null) {
        return;
      }
      this.getList();
      done();
    },
    /**刷新 */
    refreshChange() {
      this.getList();
    },
    /**搜索 */
    searchChange(params, done) {
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
  },
};
</script>